home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 June: Reference Library / Dev.CD Jun 94.toast / Periodicals / develop / develop Issue 11 / develop 11 code / The NetWork Project / Examples (Sources) / SampleTool.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-15  |  1.6 KB  |  56 lines  |  [TEXT/MPS ]

  1. /* © Copyright 1990,1991 The NetWork Project, StatLab Heidelberg. All rights reserved. */
  2. /* © Copyright 1990,1991 Joachim Lindenberg, Karlsruhe. All rights reserved. */
  3.  
  4. /* This tool demonstrates that you can
  5.   - use NetWork from C (the interfaces are yet incomplete and are subject to change)
  6.   - use SIOW based IO that allows your tool to run within and outside the MPW environment
  7.   
  8.   Currently, this tool simply gets, accepts, and destroys incoming messages.
  9.   
  10.   Note: This program only works because of the getchar() at the end !!!
  11.   Output may be garbled if messages arrive too fast.
  12. */
  13.  
  14. #include <Types.h>
  15. #include <Events.h>
  16. #include <stdio.h>
  17. #include <NetWork.h>
  18.  
  19. #define NetWorkEvent networkEvt
  20.  
  21. void HandleMsg (MsgPtr msg)
  22. {
  23.     if ((msg->MsgResult < 0) || (msg->MsgCmd & tMinorMask >= tTimeout)) DestroyMsg (msg);
  24.     else switch (msg->MsgCmd & tMajorMask) {
  25.         case tListen : printf ("got something\n"); fflush (stdout);
  26.                         GetMsg (msg, NULL, 0); AcceptMsg (msg, NULL, 0); break;
  27.         case tAccept : DestroyMsg (msg); break;
  28.         case tPost : DestroyMsg (msg); break;
  29.     };
  30. };
  31.  
  32. Boolean Filter (EventRecord *ev)
  33. {
  34.     if (ev->what == NetWorkEvent) {
  35.         HandleMsg ((MsgPtr) ev->message);
  36.         return (true);
  37.     }
  38.     return (false);
  39. }
  40. extern long __siowEventHook; /* this hook is called by SIOW with every event */
  41.  
  42. main (argc, argv)
  43. int argc; char **argv;
  44. {
  45.     printf ("Hello.\n\n");
  46.     printf ("This program demonstrates how simple it is to use a tool based approach\n\n");
  47.     fflush (stdout);
  48.     
  49.     InitNetWork (NetWorkEvent);
  50.     __siowEventHook = Filter;
  51.     while (getchar () != '\n') ;
  52.     ExitNetWork ();
  53. }
  54.  
  55.     
  56.